package com.xin.controller;
import com.xin.constants.CommonResult;
import com.xin.servie.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;

@RestController
@RequestMapping("/file")
@Api(tags = "文件相关的接口")
public class FileController {

    @Resource
    private FileService fileService;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public CommonResult<?> upload(MultipartFile file){
        return CommonResult.success(this.fileService.fileUpload(file),"上传成功");
    }


    /**
     * 删除文件
     * @param filePath
     * @return
     */
    @ApiOperation("文件删除")
    @DeleteMapping("/delete")
    public CommonResult<?> delete(String filePath){
        return this.fileService.deleteFile(filePath)?CommonResult.success(null,"文件删除成功"):CommonResult.error(499,"文件删除失败");
    }

}
